import VueRouter from "vue-router";

const router= new VueRouter({
    mode:'history',
    routes:[
        {
            name:'login',
            path:'/',
            component:()=>import('../components/User/login.vue'),
            meta:{
                title:'登录'
            }
        },
        {
            name:'register',
            path:'/register',
            component:()=>import('../components/User/register.vue'),
            meta:{
                title:'注册'
            },
            props({params:{optionsM}}){
                return{optionsM}
            }
        },{
            name:'home',
            path:'/home',
            component:()=>import('../components/view/LeftAndTop.vue'), 
            children:[
                {
                    name:'course',
                    path:'/course',
                    component:()=>import('../components/view/Course.vue'),
                    meta:{
                        title:'课程',

                    },
                    props({params:{name,code,optionsM}}){
                        return {name,code,optionsM}
                    }
                },
                {
                    name:'achievement',
                    path:'/achievement',
                    component:()=>import('../components/view/Achievement.vue'),
                    meta:{
                        title:'成绩',
                    },
                    props({params:{name,code,optionsM}}){
                        return {name,code,optionsM}
                    }
                },
                {
                    name:'selectCourse',
                    path:'/selectCourse',
                    component:()=>import('../components/view/StudentCourse.vue'),
                    meta:{
                        title:'所有课程',
                    },
                    props({params:{name,code,optionsM}}){
                        return {name,code,optionsM}
                    }
                },
                {
                    name:'userMessage',
                    path:'/userMessage',
                    component:()=>import('../components/view/UserMessage.vue'),
                    meta:{
                        title:'个人中心',
                    },
                    props({params:{name,code,optionsM}}){
                        return {name,code,optionsM}
                    }
                }
            ],
            meta:{
                title:'主页'
            },
            props({params:{name,code,optionsM}}){
                return {name,code,optionsM}
            }
        }
    ]
})
router.afterEach((to,from)=>{
    document.title=to.meta.title||'学生选课系统'//设置网页标题
})
export default router;